package com.googlecode.nacl_optimizer.tests;

import java.io.IOException;

import junit.framework.Assert;

import org.junit.Test;

import com.googlecode.nacl_optimizer.elf.StdoutParser;


public class ExtractLengthTests
{
    @Test
    public void extract_length_1()
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   20007:\t90                   \tnop" )
                , 1);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_length_2() 
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   2008f:\t83 e4 f0             \tand    $0xfffffff0,%esp"), 3);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_length_3() //
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   24359:\t8d bc 27 00 00 00 00 \tlea    0x0(%edi,%eiz,1),%edi"), 7);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_length_4()
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   34c9b:\te8 40 b5 fe ff       \tcall   201e0 <__do_global_dtors_aux>"), 5);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_length_5()
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   2460a:\tff ff ff "), 3);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_length_6()
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   248ce:\t00 "), 1);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
    
    @Test
    public void extract_length_7()
    {
        try {
        Assert.assertEquals(
                StdoutParser.extract_instruction_length( "   34cbf:\tf4                   \thlt    "), 1);
        } catch(IOException e)
        {
            Assert.fail(e.getMessage());
        }
    }
}
